package com.lcm.learn.lcmcode.sort;

import java.util.Arrays;

/**
 * @description:
 * @author: lcm
 * @create: 2020-01-20 15:52
 **/

public class SortTest {
    public static void main(String[] args){
        int retry=10,len=10000000;
        for(int a=0;a<retry;a++){
            System.out.println("---------第"+a+"轮"+"---------");
            int[] array=new int[len];
            for(int i=0;i<len;i++){
                array[i] = (int)(Math.random()*100000);
            }

            //Arrays.sort(array);

            int[] copyArray = Arrays.copyOf(array, array.length);
            System.out.println("测试："+Arrays.class.getName());
            long startTime = System.currentTimeMillis();
            Arrays.sort(copyArray);
            System.out.println("排序时间/ms："+(System.currentTimeMillis()-startTime));

            Sort[] sorts=new Sort[]{
                    //new BubbleSort(),
                    new QuickSort()};
            for(Sort sort:sorts){
                System.out.println("测试："+sort.getClass().getName());
                int[] temp = Arrays.copyOf(array, array.length);
                sortTest(temp,sort);
                System.out.println("是否正确："+Arrays.equals(temp,copyArray));
            }
        }
    }

    public static void sortTest(int[] array,Sort sort){
        long startTime = System.currentTimeMillis();
        sort.sort(array);
        System.out.println("排序时间/ms："+(System.currentTimeMillis()-startTime));
    }
}
